﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using AjaxChatService.Models;
using AjaxChatService.FacebookMessenger;
using agsXMPP;

namespace AjaxChatService.Controllers
{
    [HttpHeader("Access-Control-Allow-Origin", "*")]
    public class FBUsersController : ApiController
    {
        private FacebookUtils _helper = new FacebookUtils(); 

        // Login
        public HttpResponseMessage GetLogin(string username, string password)
        {
            username = username + "@chat.facebook.com";
            _helper.Login_Click(username, password);

            System.Threading.Thread.Sleep(1000*10);

            if (XmppClientConnections.status == "OnLogin")
                return Request.CreateResponse(HttpStatusCode.OK);

            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }

        // Logout
        public HttpResponseMessage DeleteLogOut()
        {
            _helper.Logout_Click();

            //System.Threading.Thread.Sleep(1000 * 10);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
    }
}
